package demo_table.dialog;

import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoRadioButton;
import com.lovo.netCRM.component.LovoTxt;
import demo_table.bean.StudentBean;
import demo_table.frame.TableFrame;
import demo_table.util.DataUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SelectStudentDialog extends JDialog {

    //输入框
    private LovoTxt nameText,ageText, genText, classText;

    private LovoButton lovoButton;

    private TableFrame tableFrame;

    public SelectStudentDialog(TableFrame tableFrame){

        this.tableFrame = tableFrame;
        this.setSize(500,500);
        this.setLayout(null);
        //this.setDefaultCloseOperation(3);

        nameText = new LovoTxt("学生姓名", 50, 50, this);
        //lovoRadioButton = new LovoRadioButton("性别", new String[]{"男", "女"},50, 100, this);
        ageText = new LovoTxt("年龄", 50, 100, this);
        genText = new LovoTxt("性别", 50, 150, this);
        classText = new LovoTxt("班级", 50, 200, this);
        lovoButton =  new LovoButton("确定", 50, 250, this);

        int id = tableFrame.getSdp().getLovoTable().getKey();
        if(id == -1){
            JOptionPane.showMessageDialog(null, "请先点击需要查看的学生");

        }else{
            StudentBean s = DataUtil.getStudentById(id);
            nameText.setText(s.getName());
            nameText.setEnabled(false);

            ageText.setText(s.getAge()+"");
            ageText.setEnabled(false);

            genText.setText(s.getGender());
            genText.setEnabled(false);

            classText.setText(s.getClassBean().getName());
            classText.setEnabled(false);

            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }

        this.lovoButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SelectStudentDialog.super.dispose();
                SelectStudentDialog.this.dispose();
            }
        });
    }
}
